Skip to content

fusion: pointer index nodes, small-int reads, globals by name hash - #4804

Merged
borisbat merged 2 commits into
masterfrom
fusion-at-at
Nov 26, 2026
Merged

borisbat merged 2 commits into
masterfrom
fusion-at-at

Conversation

@borisbat

Copy link
Copy Markdown
Collaborator

AOT output must be regenerated: functions that index a pointer, read a small-int element or index a global array get a new semantic hash - anyone shipping pre-generated AOT regenerates it.

Why. C-style code paid one interpreter node per step for p[i], *p = v and table[int(bytes[i])]: the Doom column loop was 10 node calls per pixel.

What changes.

  • p[i] on a pointer has fused read, by-reference and store nodes.
  • Array and fixed-array index nodes take int8/uint8/int16/uint16 elements, and a global found by name hash.
  • A cast of a small int to int/uint folds into the read below it.
  • The Global,Local stamp of binary operations and two-argument calls gets its match line.

Observable behavior.

  • dasDOOM 1000-frame timedemo, interpreter: 4.0 s -> 3.3 s, same frame hashes.
  • p[i] = uint8(v): 6.3 -> 2.6 ns; int(bytes[i]): 6.5 -> 3.4 ns.
  • log_nodes shows new node names; PtrAtR2V with a uint or 64-bit index prints PtrAtR2V_U32 / _I64 / _U64.
  • JIT and AOT execution: unchanged.

Where to look. simulate_fusion_ptr_at.cpp against SimNode_PtrAt, SimNode_Set and SimNode_Ptr2Ref, and FusionPoint_Widen with isFusedOp2, which removes a cast only over a fused read.

Validation, claims, ledger

Validation

  • All runs on one Linux x86-64 box (Ryzen 7 PRO 8700GE, clang-19, Release, the ci/release_modules.txt module set), head bf1d8e8a23.
  • The make-pr chain's full preflight stopped in the fast tier on two reds: four added lines over 100 columns (wrapped), and compile-sweep on utils/find-dupe missing its daspkg dependency on that box (installed). The two gates and every lane the red tier skipped were then run once with --only: lint, compile-sweep, tests-cpp, tests-interp, tests-jit, watchdog-interp, watchdog-jit, tests-aot, utils-tests all pass. The tests-aot lane is the test_aot run on the head commit that tests/REVIEW.md asks for.
  • Known red with its control: docs/digest reports the shipped digest stale. The baseline binary regenerates the same difference on its own tree on that box (descriptions of global constants missing), so the red does not come from this change; CI keeps that gate off. docs/sphinx-html skipped: no sphinx-build on the box. The diff touches nothing the doc workflow watches.
  • DAS_FUSION levels CI does not pair with these tests: MinSizeRel (level 1) and Debug (level 0) builds each pass the seven touched test files; the level-1 node dump shows the small-int, GlobMnh and widened-read nodes in use.
  • Negative controls, each a one-line mutation of the new C++ that makes a named test fail, then restored: store keeps a non-narrowing cast; store folds only a cast from int/uint; a cast is removed only over a fused read; fixed-array and array bounds checks with an expression index; the null check of *p = v (crashes without it); element width and sign of the widened read and of the pointer small-int load; the pointer address uses the index; the store writes the evaluated value; the Global,Local stamp reads the global (crashes when mis-stamped). 11 of 11 fail as required.
  • Node dumps (options log_nodes) confirm the tests reach what they name: FastCall2GlobLoc for f(global, local); ArrayAtR2VULocLoc<uint8> and AtR2VULocLoc<int8> under bound-check elision with no cast above; a small-int read with a 64-bit pointer index, and one through a pointer field, keep their cast.
  • Architecture citations added, each audited against src/simulate/ARCHITECTURE.md: DAS_FUSION_WIDE_NODE (simulate_fusion.h) and g_fusedSmallIntReads (simulate_fusion_widen.cpp) match #fused-small-int-reads; SimNode_PtrAtFusion (simulate_fusion_ptr_at.cpp) matches #pointer-index-family; the hook macros in simulate_fusion_op2_set_impl.h match #global-by-hash-source.
  • External review (codex), two rounds, the second on the final tip: no findings; both traces cover every changed file.
  • Micro-benchmarks, interpreter, base -> branch, ns per iteration (benchmarks/fusion/): p[i] int 4.4 -> 2.6; int(p[i]) uint8 6.9 -> 2.8; p[i] = v int 4.6 -> 2.2; *p = v 3.6 -> 2.6; lut[int(bytes[i])] 8.7 -> 5.9; global array read, local index, not solid 4.8 -> 3.5; global fixed-array read, not solid 5.4 -> 4.8; int(c) on a loop variable 3.8 -> 2.2; Doom column loop 17.8 -> 15.0; g * local under solid_context 3.0 -> 2.0. Run-to-run noise is about 0.5 ns.
  • Cost: simulate_fusion_ptr_at.cpp compiles in 5.2 s with clang-19 and its object is 3.7 MB; libDaScriptDyn.so grows from 50.1 MB to 54.0 MB.

Claims - stated, not tested

  • A fused pointer read evaluates the pointer and then the index; a fused store evaluates the value and then the address. Verified by reading: the statements are in the order of SimNode_PtrAt::compute and SimNode_Set::eval. A test would have to pin an evaluation order the language does not define across tiers. A break would show as a different element read or written when the index or the value expression changes the pointer.
  • A GlobMnh base reads the global through the hash lookup, not the stored offset. Verified by reading (computeGlobalMnh). In one context both give the same address, so no test tells them apart.
  • A uint index of 2^31 or more, and a stride * index product that wraps 32 bits, behave as on the non-fused node. Verified by reading: the address expression is the same expression with the same index type. A test would need a 2 GB buffer.
  • A 64-bit pointer index never lands on the 32-bit fused nodes. Verified by reading: PtrAtR2VName gives each index width its own node name, and only the int and uint names are registered.
  • Every element type works with every base and index pair. The tests reach every pair with int elements and every element type with a local pointer; one class template serves all of them.

Not done

  • A global by name hash as an operand of Set, the binary operations, calls and table index: only the array, fixed-array and pointer index families take it.
  • A global value read as an operand of binary operations beyond the Global,Local pair.
  • A 64-bit index on the pointer family and on small-int elements.
  • A local or constant as the stored value of a pointer store: p[i] = local still goes through the reference copy node.
  • The cast over a by-value small-int argument, a bare small-int global, and a field reached through a pointer.
  • The pointer family at DAS_FUSION 1.
  • The widened read keeps the node names GetLocalR2VToInt, GetLocalRefOffR2VToInt and GetArgumentRefOffR2VToInt although one node serves both the int and the uint cast; FusionPoint_Widen keeps its own visit for those names.
  • Defects the checklist audits found in REVIEW.md, src/REVIEW.md, tests/REVIEW.md and include/daScript/simulate/REVIEW.md themselves are not edited here.

borisbat and others added 2 commits November 26, 2026 10:29
The binary operation families and the two-argument call family each
stamp a node for a global on the left and a local on the right, but no
match line ever picked it, so the node was never created. The match
now names GetGlobalR2V with GetLocalR2V: under solid_context
`global op local` and `f(global, local)` are one node each.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
p[i] on a pointer had no fused node: every read and store paid for
the index node, the pointer read and the index read. It now has a
fused read, a read by reference and a store, from a local, argument,
global or expression pointer, with an int or uint index.

The array and fixed-array index families take int8, uint8, int16 and
uint16 elements, and a global found by name hash as a base, so a
context that is not solid fuses its global tables too.

A small int read from memory travels widened to 32 bits, so a cast of
one to int or uint changes nothing. A fused small-int read answers
evalInt and evalUInt itself: the cast over a local, a local reference
or an argument reference becomes one widened read, and the cast over a
fused index read is removed. A narrowing cast from int or uint under a
small-int pointer store is removed the same way.

SimSourceType gains sGlobalMnh, and PtrAtR2V reports its index width
in its node name, which changes the semantic hash of a function that
indexes a pointer with a uint or 64-bit index.
src/simulate/ARCHITECTURE.md states the contract. benchmarks/README.md
also gains rows for two older fusion benchmarks it did not list.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@borisbat
borisbat merged commit 1d5579a into master Nov 26, 2026
65 checks passed
@borisbat
borisbat deleted the fusion-at-at branch November 26, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant